package com.atguigu.algorithm;

import java.util.Arrays;

public class KMP1 {
    public static int[] next(String str){
        int[] res=new int[str.length()];
        for(int i=0;i<str.length();i++){
            if(i==0){
                res[i]=-1;
                continue;
            }else if(i==1){
                res[i]=0;
                continue;
            }
            //b a b a b b
            for(int j=i-1;j>=0;j--){
                String s1=str.substring(0,j);
                String s2=str.substring(i-j,i);
                if(s1.equals(s2)){
                    res[i]=j;
                    break;
                }
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] a=next(new String("bababb"));
        System.out.println(Arrays.toString(a));
    }
}
